// 保存用户相关信息的模块
import { login } from '@/api/user'
import { setToken, getToken } from '@/utils/auth'

export default {
  namespaced: true,
  state: {
    token: getToken(),
    userInfo: {}
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      setToken(token)
    }
  },
  actions: {
    async getlogin(store, data) {
      const res = await login(data)
      store.commit('setToken', res.data.jwt)
      console.log(res)
      // 保存时间戳
      localStorage.setItem('roomTime', Date.now())
    }
  }
}
